package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.dto.*;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;


/**
 * Description
 *
 * @author Zhangfei
 * @date Created on 2021/10/30
 */
@RestController
@RequestMapping("/shopping")
public class ShoppingController {

    @Reference(timeout = 3000, retries = 0, check = false)
    IProductService iProductService;


    /**
     * 根据条件查询
     *
     * @param request
     * @return
     */
    @Anoymous
    @GetMapping("/goods")
    public ResponseData getAllProduct(AllProductRequest request) {
        AllProductResponse response = iProductService.searchAllProduct(request);
        //返回数据
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            GoodsListDto goodsListDto = new GoodsListDto();
            goodsListDto.setData(response.getProductDtoList());
            goodsListDto.setTotal(response.getTotal());
            return new ResponseUtil().setData(goodsListDto);
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }


    /**
     * 推荐热门商品
     *
     * @return
     */
    @Anoymous
    @GetMapping("/recommend")
    public ResponseData getRecommendGoods() {
        RecommendResponse response = iProductService.getRecommendGoods();
        //返回数据
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }
}
